﻿<%
/**
 *	$RCSfile: uploadfile.jsp,v $
 *	$Revision: 1.4 $
 *	$Date: 2003/09/23 14:53:35 $
 */
%>

<%@	page import="com.Yasna.forum.*,
                 com.Yasna.forum.util.*,
				 com.Yasna.util.*,java.io.*,
				 com.oreilly.servlet.multipart.*"
	errorPage="error.jsp"
	contentType="text/html; charset=utf-8"
%>
				 
<%	////////////////////////
	// Authorization check
	
	// check for the existence of an authorization token
	Authorization authToken = SkinUtils.getUserAuthorization(request,response);
	
	// if the token was null, they're not authorized. Since this skin will
	// allow guests to view forums, we'll set a "guest" authentication
	// token
	if( authToken == null ) return;
	
	boolean uploadable=false;
	String message = SkinUtils.retrieve(request,response,"19ud");
	if (message!=null)	uploadable=message.equals("999");
	if (!uploadable) return;
%>

<%	///////////////////////
	// page forum variables
	
	// do not delete these
	ForumFactory forumFactory = ForumFactory.getInstance(authToken);
	User user = forumFactory.getProfileManager().getUser(authToken.getUserID());
%>

<%	/////////////////
	// get parameters
		request.setCharacterEncoding("UTF-8");
	int forumID = ParamUtils.getIntParameter(request,"forum",-1);
	boolean doPost = ParamUtils.getBooleanParameter(request,"doPost");
%>




<%	/////////////////////////
	// Create the new message
	boolean errors = false;
	String errorMessage = "";	
	String uploadURL="";
	if( forumID==-1 ) {
		doPost=true;
		// Create a new message object
			
      MultipartParser mp = new MultipartParser(request, 30*1024*1024); // 10MB
	  mp.setEncoding("UTF-8");
      Part part;
      while ((part = mp.readNextPart()) != null) {
        String name = part.getName();
        if (part.isParam() && name.equals("forum")) {
          // it's a parameter part
          ParamPart paramPart = (ParamPart) part;
          String value = paramPart.getStringValue();
          forumID=Integer.parseInt(value);
        }
        else if (part.isFile()) {
          // it's a file part
          FilePart filePart = (FilePart) part;
          String fileName = filePart.getFileName();
          String dirName="e:\\upload\\"
			+Integer.toString(forumID)+"\\"
			+Integer.toString(user.getID());
          if (fileName != null) {
            // the part actually contained a file
             File dir = new File(dirName);
             if (!dir.exists()) dir.mkdirs();
            filePart.writeTo(dir);
	      uploadURL="http://www.yuanma.com.cn/upload/"
       			+Integer.toString(forumID)+"/"
			+Integer.toString(user.getID())+"/"+fileName;
          }
   
        }
      }
	}
%>

<HTML>

<head>
	<title>文件上传</title>
	<link rel="stylesheet" href="style/global.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>

<p>				 
			 


<%	if( errors ) { %>
<h4 class="error"><i><%= errorMessage %></i></h4>
<%	} %>

<form action="uploadfile.jsp" name="uploadForm" method="post" ENCTYPE="multipart/form-data">
<input type="hidden" name="doPost" value="true">
<input type="hidden" name="forum" value="<%= forumID %>">


<table cellpadding="5" cellspacing="5" border="0">

<tr>
	<td valign="top">选择需要上传的文件：</td>
</tr>
<tr>
	<td><INPUT TYPE=FILE NAME=file1></td>
</tr>
<tr>

	<td><input type="submit" value="确认">
		&nbsp;
		<input type="submit" value="关闭" onclick="location.href='javascript:window.close()';return false;">
	</td>
</tr>
<% if(doPost) {%>
<tr>
	  <td valign="top">已成功上传，请将以下文件地址粘贴到您发布的消息中作为下载链接：</td>
</tr>
<tr bgcolor=\"#eeeeee\">

	<td><%= uploadURL %></td>
</tr>
<tr>
	  <td>&nbsp;</td>
</tr>

<%}%>

</table>

</form>


<br clear="all">
	
</html>
